package com.ruoyi.project.module.whd.review;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.project.domain.YhAppointment;
import com.ruoyi.project.service.ISysRoleService;
import com.ruoyi.project.service.IYhAppointmentService;

import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.ruoyi.common.security.utils.SecurityUtils.*;

/**
 * 预约信息Controller
 *
 * @author ruoyi
 * @date 2023-03-07
 */
@RestController
@RequestMapping("/whd/appointment")
public class WhdYhAppointmentController extends BaseController {
    @Autowired
    private IYhAppointmentService yhAppointmentService;
    @Autowired
    private ISysRoleService roleService;
    /**
     * 查询预约信息列表
     */
    /*@RequiresPermissions("whd:appointment:list")*/
    @GetMapping("/list")
    public TableDataInfo list(YhAppointment yhAppointment) {
        // 获取当前用户信息
        String userID = getUsername();
        if (!userID.equals("admin")) {
            yhAppointment.setAssistId(userID);

        }
        startPage();
        List<YhAppointment> list = yhAppointmentService.selectYhAppointmentList(yhAppointment);

       /* for (int i=0;i<list.size();i++){

            if(list.get(i).getEquipmentType().equals("001")){
                list.get(i).setEquipmentType("成分分析");
            }else if(list.get(i).getEquipmentType().equals("002")){
                list.get(i).setEquipmentType("微区分析");
            }else if(list.get(i).getEquipmentType().equals("003")){
                list.get(i).setEquipmentType("感官分析");
            }else if(list.get(i).getEquipmentType().equals("004")){
                list.get(i).setEquipmentType("物性分析");
            }else if(list.get(i).getEquipmentType().equals("005")){
                list.get(i).setEquipmentType("分子生物学分析");
            }else if(list.get(i).getEquipmentType().equals("006")){
                list.get(i).setEquipmentType("微生物分析");
            }else if(list.get(i).getEquipmentType().equals("007")){
                list.get(i).setEquipmentType("常规分析");
            }else if(list.get(i).getEquipmentType().equals("008")){
                list.get(i).setEquipmentType("前处理仪器设备");
            }else if(list.get(i).getEquipmentType().equals("009")){
                list.get(i).setEquipmentType("离心分离分析");
            }else if(list.get(i).getEquipmentType().equals("010")){
                list.get(i).setEquipmentType("分析软件");
            }else if(list.get(i).getEquipmentType().equals("011")){
                list.get(i).setEquipmentType("其他");
            }else if(list.get(i).getEquipmentType().equals("012")){
                list.get(i).setEquipmentType("会议室");
            }

        }*/
        return getDataTable(list);
    }

    /**
     * 导出预约信息列表
     */
    /*@RequiresPermissions("whd:appointment:export")*/
    @Log(title = "预约信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhAppointment yhAppointment) {
        List<YhAppointment> list = yhAppointmentService.selectYhAppointmentList(yhAppointment);
        ExcelUtil<YhAppointment> util = new ExcelUtil<YhAppointment>(YhAppointment.class);
        util.exportExcel(response, list, "预约信息数据");
    }

    /**
     * 获取预约信息详细信息
     */
    /*@RequiresPermissions("whd:appointment:query")*/
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(yhAppointmentService.selectYhAppointmentById(id));
    }

    /**
     * 新增预约信息
     */
   /* @RequiresPermissions("whd:appointment:add")*/
    @Log(title = "预约信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhAppointment yhAppointment) {
        return toAjax(yhAppointmentService.insertYhAppointment(yhAppointment));
    }

    /**
     * 修改预约信息
     */
   /* @RequiresPermissions("whd:appointment:edit")*/
    @Log(title = "预约信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhAppointment yhAppointment) {
        /**
         * 发送企业微信通知
         */
        WhdWeChatMassage.sendWeChatMassage(yhAppointment);
        yhAppointment.setAssistTime(DateUtils.getNowDate());
        return toAjax(yhAppointmentService.updateYhAppointment(yhAppointment));
    }

    /**
     * 删除预约信息
     */
    /*@RequiresPermissions("whd:appointment:remove")*/
    @Log(title = "预约信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(yhAppointmentService.deleteYhAppointmentByIds(ids));
    }

}
